package com.wbao.dianniu.manager;

import android.content.Context;

import com.wbao.dianniu.http.Batch;
import com.wbao.dianniu.http.Command;
import com.wbao.dianniu.http.HttpUtil;
import com.wbao.dianniu.http.HttpUtil.MyResponse;
import com.wbao.dianniu.listener.IActivityDel;
import com.wbao.dianniu.listener.IActivityDelListener;
import com.wbao.dianniu.logical.Action;
import com.wbao.dianniu.logical.GlobalContext;

import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;

/**
 * 简历列表
 * 
 * @author yejianjun
 *
 */
public class ActivityDelManager implements IActivityDel {

	private IActivityDelListener mListener;
	private Context mContext;
	
	public ActivityDelManager(Context context) {
		mContext = context;
	}

	@Override
	public void activityDel(int accountId, int activityId) {
		// TODO Auto-generated method stub
		StringEntity stringEntity = null;
		try {
			Batch batch = new Batch();
			batch.setToken(GlobalContext.getCacheToken());
			Command command = new Command();
			command.addAction(Action.ACCOUNT_ACTIVITY_DEL)
					.addArgs("accountId", accountId)
					.addArgs("activityId", activityId);
			batch.addCommand(command);
			stringEntity = new StringEntity(batch.toJson(), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		HttpUtil http = new HttpUtil();
		http.req(mContext, stringEntity, new MyResponse() {

			@Override
			public void responseSucess(Object obj) {
				// TODO Auto-generated method stub
				if (null != mListener)
					mListener.onActivityDelSuccess();
			}

			@Override
			public void responseFailure(int errorCode, String msg) {
				// TODO Auto-generated method stub
				if (null != mListener)
					mListener.onActivityDelFailure(errorCode, msg);
			}
		});
	}

	@Override
	public boolean addActivityDelListener(IActivityDelListener listener) {
		mListener = listener;
		return mListener == null ? false : true;
	}

	@Override
	public boolean removeActivityDelListener(IActivityDelListener listener) {
		if (null == listener)
			return false;
		mListener = null;
		return true;
	}

}
